# CMakeList.txt: AiBox 的 CMake 项目，在此处包括源代码并定义
cmake_minimum_required (VERSION 3.8)

# 使用C++11标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# ws2def.h重定义
if(WIN32)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  /DWIN32_LEAN_AND_MEAN")
endif()

# 追加CMake查找目录
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cmake")

# MYSQL变量设置
if(WIN32)
	#set(MYSQL_DIR "C:/Program Files/MySQL/MySQL Server 5.7")
	set(MYSQL_INCLUDE_DIR "C:/Program Files/MySQL/MySQL Server 5.7/include")
	set(MYSQL_LIB_DIR "C:/Program Files/MySQL/MySQL Server 5.7/lib")
	set(MYSQL_VERSION 5.7)
endif()

# 查找MySQL包
find_package(MySQL REQUIRED)

# windows平台
if(WIN32)
	# 设置boost根目录
	set(BOOST_ROOT "E:/boost_1_63_0")
	# 设置boost库目录
	set(BOOST_LIBRARYDIR "E:/boost_1_63_0/stage/64")
	# 设置OpenCV的路径
	set(OpenCV_DIR "D:/opencv/opencv-4.8.1/build/install")
elseif(UNIX)
	# 设置boost根目录
	set(BOOST_ROOT /usr/local)
	# 设置boost库目录
	set(BOOST_LIBRARYDIR /usr/local/lib)
endif()

# 只搜索上语句设置的搜索路径
set(Boost_NO_SYSTEM_PATHS ON)
# 设置使用静态库的boost库
set(Boost_USE_STATIC_LIBS ON)
# 打印boost搜索详情日志
set(Boost_DEBUG ON)

# 查找boost库
find_package(Boost COMPONENTS system filesystem regex date_time chrono serialization thread REQUIRED)

# 查找oatpp依赖
find_package(oatpp REQUIRED)

# 查找oatpp-websocket依赖
find_package(oatpp-websocket REQUIRED)

# 查找opencv依赖
find_package(OpenCV REQUIRED)

# 设置源码列表变量
file(GLOB LOCAL_SOURCES_DIR ./*.cpp ./db/*.cpp ./util/*.cpp 
	./config/*.cpp ./entity/*.cpp ./service/*.cpp ./http/*.cpp 
	./log/*.cpp ./socket/*.cpp ./ai/*.cpp ./video/*.cpp 
	./record/*.cpp)
file(GLOB LOCAL_INCLUDE_DIR ./*.h ./db/*.h ./util/*.h 
	./config/*.h ./entity/*.h ./service/*.h ./http/*.h 
	./log/*.h ./socket/*.h ./ai/*.h ./video/*.h ./dto/*.h 
	./vo/*.h ./record/*.h ./common/*.h)

# 设置源码列表变量
#set(AI_BOX_MODULES db util config entity service http log socket ai video dto vo record common)
#set(AI_BOX_SRC_FILES)
#set(AI_BOX_SRC_INCLUDE_FILES)

# 包含模块源文件
#foreach (module ${AI_BOX_MODULES})
    #FILE(GLOB_RECURSE BOX_INCLUDE_${module}_FILES ./${module}/*.h)
    #LIST(APPEND AI_BOX_SRC_INCLUDE_FILES ${BOX_INCLUDE_${module}_FILES})

    #FILE(GLOB_RECURSE BOX_SRC_${module}_FILES ./${module}/*.cpp)
    #LIST(APPEND AI_BOX_SRC_FILES ${BOX_SRC_${module}_FILES})
#endforeach ()

if(WIN32)
	# 添加boost库依赖头文件
	include_directories("./3rdparty/pthreads")
endif()

# 系统日志头文件
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/spdlog-1.10.0/include")
# 添加mysql头文件
include_directories(${MYSQL_INCLUDE_DIRS})
# 添加boost头文件
include_directories(${Boost_INCLUDE_DIRS})
# 指定自定义boost的链接目录(非find_package自动查找到自定义库)
link_directories(${Boost_LIBRARY_DIRS})
# 添加opencv头文件
include_directories( ${OpenCV_INCLUDE_DIRS} )

# 解决sqlite引用错误:dlclose@@GLIBC_2.2.5
if(UNIX)
	set (CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl") 
endif()

# 将源代码添加到此项目的可执行文件。
add_executable (AiBox ${LOCAL_SOURCES_DIR} ${LOCAL_INCLUDE_DIR})
# 目标连接boost库
target_link_libraries(AiBox PRIVATE
	${Boost_FILESYSTEM_LIBRARY}
	${Boost_SYSTEM_LIBRARY}
	${Boost_REGEX_LIBRARY}
	${Boost_CHRONO_LIBRARY}
	${Boost_SERIALIZATION_LIBRARY}
	${Boost_THREAD_LIBRARY}
	${Boost_DATE_TIME_LIBRARY}
	${MYSQL_LIBRARIES}
	${OpenCV_LIBS}
	sqlite3
	oatpp::oatpp
	oatpp::oatpp-websocket
)
